package project.dao.impl;

import Utils.db.dao.BaseDAO;
import project.dao.OrderItemDAO;
import project.pojo.OrderItem;

import java.util.List;

public class OrderItemDAOImpl extends BaseDAO implements OrderItemDAO {
    @Override
    public int addOrderItem(OrderItem item) {
        String sql = "insert into t_order_item (name, count, price, total_price, order_id) values (?,?,?,?,?)";
        return update(sql, item.getName(), item.getCount(), item.getPrice(), item.getTotalPrice(), item.getOrderId());
    }

    @Override
    public int[] addOrderItems(List<OrderItem> items) throws NoSuchFieldException, IllegalAccessException {
        String sql = "insert into t_order_item (name, count, price, total_price, order_id) values (?,?,?,?,?)";
        return updateBatch(sql, items, new String[]{"name", "count", "price", "totalPrice", "orderId"});
    }
}
